package com.xhs.controller;

import com.xhs.dto.request.LoginStrategyRequest;
import com.xhs.message.ReturnResult;
import com.xhs.service.StrategyLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @desc: 策略模式
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2022/12/4 23:17
 * @version: JDK 1.8
 */
@RestController
@RequestMapping("/strategy")
public class StrategyController {

    @Autowired
    private Map<String, StrategyLoginService> loginStrategyServiceMap;

    /**
     * 策略模式登录
     *
     * @param loginRequest
     * @return
     */
    @PostMapping("/login")
    public ReturnResult<String> login(@RequestBody LoginStrategyRequest loginRequest) {
        // 使用策略模式解决多重if判断
        StrategyLoginService loginService = loginStrategyServiceMap.get(loginRequest.getLoginType());
        String login = loginService.login();
        return ReturnResult.success(login);
    }
}
